package com.iplant.ams.service.po.dms.maintenance;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.ams.service.basicenum.dms.DMSItemTaskStatus;
import com.iplant.ams.service.basicenum.dms.DMSMaintenanceLevel;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.po.DBBasePO;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.join.DBJoin;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;

/**
 * 保养工单子任务(构型层)
 *
 * @author YouWang·Peng
 * 2022-8-8 09:20:21
 */
@DBBasePO(TableName = "dms_maintenance_item_task", Schemas = DBSchemas.AMS, CheckName = {"Code"}, CodePrefix
        = "DMIT-{yyyyMM}", Name = false, CodeAuto = true)
public class DMSMaintenanceItemTask extends BasePO implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 保养主任务ID
     **/
    @DBCondition
    @DBField
    public int TaskID = 0;
    /**
     * 主任务工单号
     **/
    @DBJoin(name = "Code", tableName = "dms_maintenance_task", tableAsName = "dms_maintenance_task1", Schemas =
            DBSchemas.AMS,
            MainTableField = "TaskID")
    public String TaskCode = "";
    /**
     * 设备ID
     **/
    @DBField
    @DBCondition
    public int DeviceID = 0;
    @DBJoin(name = "AssetInfoID", tableName = "dms_device_ledger", tableAsName = "dms_device_ledger1", Schemas =
            DBSchemas.AMS,
            MainTableField = "DeviceID")
    public int AssetInfoID = 0;

    /**
     * 设备名称
     **/
    @DBJoin(name = "Name", tableName = "ams_asset_list", tableAsName = "ams_asset_list1", Schemas = DBSchemas.AMS,
            JoinIndex = 2,
            ConditionalJoin = "dms_device_ledger1.AssetInfoID=ams_asset_list1.ID")
    public String DeviceName = "";
    /**
     * 设备编码
     **/
    @DBJoin(name = "Code", tableName = "ams_asset_list", tableAsName = "ams_asset_list1", Schemas = DBSchemas.AMS,
            JoinIndex = 2,
            ConditionalJoin = "dms_device_ledger1.AssetInfoID=ams_asset_list1.ID")
    public String DeviceCode = "";
    /**
     * 保养项ID
     **/
    @DBField
    @DBCondition
    public int MaintenanceItemID = 0;
    /**
     * 保养项名称
     **/
    @DBJoin(name = "Name", tableName = "dms_maintenance_item", tableAsName = "dms_maintenance_item1", Schemas =
            DBSchemas.AMS,
            MainTableField = "MaintenanceItemID")
    public String MaintenanceItemName = "";
    @DBJoin(name = "Code", tableName = "dms_maintenance_item", tableAsName = "dms_maintenance_item1", Schemas =
            DBSchemas.AMS,
            MainTableField = "MaintenanceItemID")
    public String MaintenanceItemCode = "";

    @DBJoin(name = "SOPList", tableName = "dms_maintenance_item", tableAsName = "dms_maintenance_item1", Schemas =
            DBSchemas.AMS,
            MainTableField = "MaintenanceItemID")
    public List<String> SOPList = new ArrayList<>();

    /**
     * 保养项类型
     */
    @DBJoin(name = "Type", tableName = "dms_maintenance_item", tableAsName = "dms_maintenance_item1", Schemas =
            DBSchemas.AMS,
            MainTableField = "MaintenanceItemID")
    public int MaintenanceItemType = 0;

    /**
     * 保养等级枚举
     */
    @DBCondition
    @DBJoin(name = "MaintenanceLevel", tableName = "dms_maintenance_item", tableAsName = "dms_maintenance_item1",
            Schemas =
                    DBSchemas.AMS,
            MainTableField = "MaintenanceItemID")
    public int MaintenanceLevel = 0;

    /**
     * 保养等级文本
     */
    public String MaintenanceLevelText = "";

    /**
     * 保养项描述
     **/
    @DBJoin(name = "Description", tableName = "dms_maintenance_item", tableAsName = "dms_maintenance_item1", Schemas
            = DBSchemas.Basic,
            MainTableField = "MaintenanceItemID")
    public String MaintenanceItemDescription = "";

    /**
     * 构型ID
     **/
    @DBField
    @DBCondition
    public int ConfigurationID = 0;
    /**
     * 构型名称
     **/
    @DBJoin(name = "Name", tableName = "dms_configuration", tableAsName = "dms_configuration1", Schemas = DBSchemas.AMS,
            MainTableField = "ConfigurationID")
    public String ConfigurationName = "";
    @DBJoin(name = "Code", tableName = "dms_configuration", tableAsName = "dms_configuration1", Schemas = DBSchemas.AMS,
            MainTableField = "ConfigurationID")
    public String ConfigurationCode = "";

    /**
     * 保养项
     **/
    public DMSMaintenanceItem MaintenanceItem = new DMSMaintenanceItem();

    /**
     * 派工人ID
     **/
    @DBField
    @DBCondition
    public int DispatchPersonID = 0;
    /**
     * 派工人名称
     **/
    @DBJoin(name = "Name", tableName = "mbs_user", tableAsName = "mbs_user1", Schemas = DBSchemas.Basic,
            MainTableField = "DispatchPersonID")
    public String DispatchPersonName = "";
    /**
     * 派工时刻
     **/
    @DBField
    public Calendar DispatchTime = Calendar.getInstance();
    /**
     * 派工人备注
     **/
    @DBField
    public String DispatchRemark = "";
    /**
     * 保养人ID
     **/
    @DBField
    @DBCondition
    public int WorkerID = 0;
    /**
     * 保养人名称
     **/
    @DBJoin(name = "Name", tableName = "mbs_user", tableAsName = "mbs_user2", Schemas = DBSchemas.Basic,
            MainTableField = "WorkerID")
    public String WorkerName = "";
    /**
     * 保养时刻
     **/
    @DBField
    public Calendar WorkerTime = Calendar.getInstance();
    /**
     * 保养备注
     **/
    @DBField
    public String WorkerRemark = "";
    /**
     * 检验员ID
     **/
    @DBCondition
    @DBField
    public int CheckerID = 0;
    /**
     * 检验员名称
     **/
    @DBJoin(name = "Name", tableName = "mbs_user", tableAsName = "mbs_user3", Schemas = DBSchemas.Basic,
            MainTableField = "CheckerID")
    public String CheckerName = "";
    /**
     * 检验时刻
     **/
    @DBField
    public Calendar CheckerTime = Calendar.getInstance();
    /**
     * 检验员备注
     **/
    @DBField
    public String CheckerRemark = "";
    /**
     * 子任务状态
     **/
    @DBCondition
    @DBField
    public int Status = 0;
    /**
     * 子任务备注
     **/
    @DBField
    public String Remark = "";
    /**
     * 保养结果
     **/
    @DBCondition
    @DBField
    public int Result = 0;
    /**
     * 上传图片
     **/
    @DBField
    public List<String> ImageList = new ArrayList<>();
    /**
     * 创建时刻文本
     **/
    public String CreateTimeText = "";
    /**
     * 编辑日期文本
     **/
    public String WorkerTimeText = "";
    /**
     * 结果文本
     **/
    public String ResultText = "";
    /**
     * 状态文本
     **/
    public String StatusText = "";
    /**
     * 结果显示效果
     **/
    public String Type = "";
    /**
     * 状态显示效果
     **/
    public String StatusType = "";
    /**
     * 上次保养时间
     **/
    public String LastMaintenanceTime = "";
    /**
     * 登录人ID
     **/
    public int LoginID = 0;

    /**
     * 计划保养日期
     */
    @DBField
    public Calendar PlanDate = Calendar.getInstance();

    @JsonProperty("PlanDate")
    public Calendar getPlanDate() {
        return PlanDate;
    }

    public void setPlanDate(Calendar planDate) {
        PlanDate = planDate;
    }

    @JsonProperty("TaskID")
    public int getTaskID() {
        return TaskID;
    }

    public void setTaskID(int taskID) {
        TaskID = taskID;
    }

    @JsonProperty("TaskCode")
    public String getTaskCode() {
        return TaskCode;
    }

    public void setTaskCode(String taskCode) {
        TaskCode = taskCode;
    }

    @JsonProperty("DeviceID")
    public int getDeviceID() {
        return DeviceID;
    }

    public void setDeviceID(int deviceID) {
        DeviceID = deviceID;
    }

    @JsonProperty("DeviceName")
    public String getDeviceName() {
        return DeviceName;
    }

    public void setDeviceName(String deviceName) {
        DeviceName = deviceName;
    }

    @JsonProperty("DeviceCode")
    public String getDeviceCode() {
        return DeviceCode;
    }

    public void setDeviceCode(String deviceCode) {
        DeviceCode = deviceCode;
    }

    @JsonProperty("MaintenanceItemID")
    public int getMaintenanceItemID() {
        return MaintenanceItemID;
    }

    public void setMaintenanceItemID(int maintenanceItemID) {
        MaintenanceItemID = maintenanceItemID;
    }

    @JsonProperty("MaintenanceItemName")
    public String getMaintenanceItemName() {
        return MaintenanceItemName;
    }

    public void setMaintenanceItemName(String maintenanceItemName) {
        MaintenanceItemName = maintenanceItemName;
    }

    @JsonProperty("MaintenanceItemCode")
    public String getMaintenanceItemCode() {
        return MaintenanceItemCode;
    }

    public void setMaintenanceItemCode(String maintenanceItemCode) {
        MaintenanceItemCode = maintenanceItemCode;
    }

    @JsonProperty("MaintenanceItemDescription")
    public String getMaintenanceItemDescription() {
        return MaintenanceItemDescription;
    }

    public void setMaintenanceItemDescription(String maintenanceItemDescription) {
        MaintenanceItemDescription = maintenanceItemDescription;
    }

    @JsonProperty("ConfigurationID")
    public int getConfigurationID() {
        return ConfigurationID;
    }

    public void setConfigurationID(int configurationID) {
        ConfigurationID = configurationID;
    }

    @JsonProperty("ConfigurationName")
    public String getConfigurationName() {
        return ConfigurationName;
    }

    public void setConfigurationName(String configurationName) {
        ConfigurationName = configurationName;
    }

    @JsonProperty("ConfigurationCode")
    public String getConfigurationCode() {
        return ConfigurationCode;
    }

    public void setConfigurationCode(String configurationCode) {
        ConfigurationCode = configurationCode;
    }

    @JsonProperty("MaintenanceItem")
    public DMSMaintenanceItem getMaintenanceItem() {
        return MaintenanceItem;
    }

    public void setMaintenanceItem(DMSMaintenanceItem maintenanceItem) {
        MaintenanceItem = maintenanceItem;
    }

    @JsonProperty("DispatchPersonID")
    public int getDispatchPersonID() {
        return DispatchPersonID;
    }

    public void setDispatchPersonID(int dispatchPersonID) {
        DispatchPersonID = dispatchPersonID;
    }

    @JsonProperty("DispatchPersonName")
    public String getDispatchPersonName() {
        return DispatchPersonName;
    }

    public void setDispatchPersonName(String dispatchPersonName) {
        DispatchPersonName = dispatchPersonName;
    }

    @JsonProperty("DispatchTime")
    public Calendar getDispatchTime() {
        return DispatchTime;
    }

    public void setDispatchTime(Calendar dispatchTime) {
        DispatchTime = dispatchTime;
    }

    @JsonProperty("DispatchRemark")
    public String getDispatchRemark() {
        return DispatchRemark;
    }

    public void setDispatchRemark(String dispatchRemark) {
        DispatchRemark = dispatchRemark;
    }

    @JsonProperty("WorkerID")
    public int getWorkerID() {
        return WorkerID;
    }

    public void setWorkerID(int workerID) {
        WorkerID = workerID;
    }

    @JsonProperty("WorkerName")
    public String getWorkerName() {
        return WorkerName;
    }

    public void setWorkerName(String workerName) {
        WorkerName = workerName;
    }

    @JsonProperty("WorkerTime")
    public Calendar getWorkerTime() {
        return WorkerTime;
    }

    public void setWorkerTime(Calendar workerTime) {
        WorkerTime = workerTime;
    }

    @JsonProperty("WorkerRemark")
    public String getWorkerRemark() {
        return WorkerRemark;
    }

    public void setWorkerRemark(String workerRemark) {
        WorkerRemark = workerRemark;
    }

    @JsonProperty("CheckerID")
    public int getCheckerID() {
        return CheckerID;
    }

    public void setCheckerID(int checkerID) {
        CheckerID = checkerID;
    }

    @JsonProperty("CheckerName")
    public String getCheckerName() {
        return CheckerName;
    }

    public void setCheckerName(String checkerName) {
        CheckerName = checkerName;
    }

    @JsonProperty("CheckerTime")
    public Calendar getCheckerTime() {
        return CheckerTime;
    }

    public void setCheckerTime(Calendar checkerTime) {
        CheckerTime = checkerTime;
    }

    @JsonProperty("CheckerRemark")
    public String getCheckerRemark() {
        return CheckerRemark;
    }

    public void setCheckerRemark(String checkerRemark) {
        CheckerRemark = checkerRemark;
    }

    @JsonProperty("Status")
    public int getStatus() {
        return Status;
    }

    public void setStatus(int status) {
        Status = status;
    }

    @JsonProperty("Remark")
    public String getRemark() {
        return Remark;
    }

    public void setRemark(String remark) {
        Remark = remark;
    }

    @JsonProperty("Result")
    public int getResult() {
        return Result;
    }

    public void setResult(int result) {
        Result = result;
    }

    @JsonProperty("ImageList")
    public List<String> getImageList() {
        return ImageList;
    }

    public void setImageList(List<String> imageList) {
        ImageList = imageList;
    }

    @JsonProperty("CreateTimeText")
    public String getCreateTimeText() {
        return CreateTimeText;
    }

    public void setCreateTimeText(String createTimeText) {
        CreateTimeText = createTimeText;
    }

    @JsonProperty("WorkerTimeText")
    public String getWorkerTimeText() {
        SimpleDateFormat wSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String wCurrentTime = wSDF.format(Calendar.getInstance().getTime());
        Calendar wBaseTime = Calendar.getInstance();
        wBaseTime.set(2010, 0, 1, 0, 0, 0);
        if (WorkerTime.compareTo(wBaseTime) > 0) {
            WorkerTimeText = wSDF.format(WorkerTime.getTime());
        } else {
            WorkerTimeText = "-";
        }

        return WorkerTimeText;
    }

    public void setWorkerTimeText(String workerTimeText) {
        WorkerTimeText = workerTimeText;
    }

    @JsonProperty("ResultText")
    public String getResultText() {
        ResultText = Result == 1 ? "合格" : "不合格";
        return ResultText;
    }

    public void setResultText(String resultText) {
        ResultText = resultText;
    }

    @JsonProperty("StatusText")
    public String getStatusText() {
        if (Status > 0) {
            StatusText = Objects.requireNonNull(DMSItemTaskStatus.getEnumType(Status)).getLabel();
        }
        return StatusText;
    }

    public void setStatusText(String statusText) {
        StatusText = statusText;
    }

    @JsonProperty("Type")
    public String getType() {
        return Type;
    }

    public void setType(String type) {
        Type = type;
    }

    @JsonProperty("StatusType")
    public String getStatusType() {
        return StatusType;
    }

    public void setStatusType(String statusType) {
        StatusType = statusType;
    }

    @JsonProperty("LastMaintenanceTime")
    public String getLastMaintenanceTime() {
        return LastMaintenanceTime;
    }

    public void setLastMaintenanceTime(String lastMaintenanceTime) {
        LastMaintenanceTime = lastMaintenanceTime;
    }

    @JsonProperty("LoginID")
    public int getLoginID() {
        return LoginID;
    }

    public void setLoginID(int loginID) {
        LoginID = loginID;
    }

    @JsonProperty("AssetInfoID")
    public int getAssetInfoID() {
        return AssetInfoID;
    }

    public void setAssetInfoID(int assetInfoID) {
        AssetInfoID = assetInfoID;
    }

    @JsonProperty("MaintenanceItemType")
    public int getMaintenanceItemType() {
        return MaintenanceItemType;
    }

    public void setMaintenanceItemType(int maintenanceItemType) {
        MaintenanceItemType = maintenanceItemType;
    }

    @JsonProperty("MaintenanceLevel")
    public int getMaintenanceLevel() {
        return MaintenanceLevel;
    }

    public void setMaintenanceLevel(int maintenanceLevel) {
        MaintenanceLevel = maintenanceLevel;
    }

    @JsonProperty("MaintenanceLevelText")
    public String getMaintenanceLevelText() {
        MaintenanceLevelText = DMSMaintenanceLevel.getEnumType(MaintenanceLevel).getLabel();
        return MaintenanceLevelText;
    }

    public void setMaintenanceLevelText(String maintenanceLevelText) {
        MaintenanceLevelText = maintenanceLevelText;
    }

    @JsonProperty("SOPList")
    public List<String> getSOPList() {
        return SOPList;
    }

    public void setSOPList(List<String> SOPList) {
        this.SOPList = SOPList;
    }
}
